
$(function(){
	$("#user").val("");
	$("#pwd").val("");
	$("#pwd_twice").val("");
	my_focus("user");
	my_focus("pwd");
	my_focus("pwd_twice");
	
	$("#user").blur(function(){
		var email=$("#user").val();
		if(email==""){
			$("#user").css("border","1px solid red");
			return;
		}else{
			//验证是否已经注册了
			$.post("../json/userInfoAction_registerTest?t="+new Date(),{'userInfo.w_email':email},function(data){
				if(data.result==1){
					$("#user").css("border","1px solid green");	
				}else{
					$("#user").css("border","1px solid red");
				}
			});//发送请求
		}
	});

	$("#pwd").blur(function(){
		var pwd=$("#pwd").val();
		if(pwd==""){
			$("#pwd").css("border","1px solid red");
		}else{
			var reg=/[0-9A-Za-z_]{6,16}/ig;
			if(reg.test(pwd))
			{
				$("#pwd").css("border","1px solid green");
			}
			else
			{
				$("#pwd").css("border","1px solid green");
			}
		}
	});
	
	$("#pwd_twice").blur(function(){
		var pwd=$("#pwd").val();
		var pwd_twice=$("#pwd_twice").val();
		if(pwd!=pwd_twice || pwd==""){
			$("#pwd_twice").css("border","1px solid red");		
		}else{
			$("#pwd_twice").css("border","1px solid green");	
		}
	});
	
	$("#checkNum").blur(function(){
		$("#pwd_twice").css("border","1px solid green");	
	});
});

function my_focus(id){
	$("#"+id).focus(function(){
		$("#"+id).css("border","1px solid blue");
	});
}
//发送邮件
var time=120;
var mytime;
function sendCode(){
	var email=$("#user").val();
	if(email==""){
		$("#user").css("border","1px solid red");
		return ;
	}else{
		$.post("../json/userInfoAction_sendCode?t="+new Date(),{'userInfo.w_email':email},function(data){
			if(data.result==1)
			{
				$("#sendEmail").val("重新发送（120s）");
				mytime=setInterval("checkTime()", 1000);
			}
			else
			{
				$("#sendEmail").val("邮件发送失败");
			}
		});
	}
}
//倒计时
function checkTime(){
	time--;
	$("#sendEmail").val("重新发送("+time+"s)");
	if(time<0)
	{
		$("#sendEmail").val("发送验证码");
		clearInterval(mytime);
	}
}
//注册
function register(){
	var email=$("#user").val()
	var pwd=$("#pwd").val();
	var pwd_twice=$("#pwd_twice").val();
	var checkNum=$("#checkNum").val();
	$.post("../json/userInfoAction_register?t="+new Date(),{'userInfo.w_email':email,'userInfo.w_pwd':pwd,'checkNum':checkNum},function(data){
		if(data.result==0)
		{
			alert("注册失败");
		}
		else if(data.result==1)
		{
			location.href="../login/login.html";
		}
		else if(data.result==2)
		{
			$("#checkNum").css("border","1px solid red").select();
		}
	});	
}
